package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.CommonSugar;
import com.useeinfo.framework.sugar.tools.StringConverters;

import javax.persistence.*;

/**
 * @Auther: xudong.sun
 * @Date: 2018/11/30 09:54
 * @Description: 设备类型表
 */
@Entity
@Table(name = "facility_cat")
public class FacilityCat extends SuperClassEntity<FacilityCat> {

    /**
     * 类型名称
     */
    private String catName;

    /**
     * 组织左
     */
    private Integer lft;
    /**
     * 组织右
     */
    private Integer rgt;
    /**
     * 等级
     */
    private Integer lvl;

    /**
     * 上级分类
     */
    private Long parentId;

    /**
     * 所有上级id，使用逗号分隔
     */
    @Column(length = 500)
    private String parentIds;

    private String description;

    /**
     * 创建人ID
     */
    private Long systemUserId;
    /**
     * 创建人姓名
     */
    private String systemUserName;

    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public String getCatName() {
        return catName;
    }

    public void setCatName(String catName) {
        this.catName = catName;
    }


    public String getParentIds() {
        return parentIds;
    }

    public void setParentIds(String parentIds) {
        this.parentIds = parentIds;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getLft() {
        return lft;
    }

    public void setLft(Integer lft) {
        this.lft = lft;
    }

    public Integer getRgt() {
        return rgt;
    }

    public void setRgt(Integer rgt) {
        this.rgt = rgt;
    }

    public Integer getLvl() {
        return lvl;
    }

    public void setLvl(Integer lvl) {
        this.lvl = lvl;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public Long getSystemUserId() {
        return systemUserId;
    }

    public void setSystemUserId(Long systemUserId) {
        this.systemUserId = systemUserId;
    }

    public String getSystemUserName() {
        return systemUserName;
    }

    public void setSystemUserName(String systemUserName) {
        this.systemUserName = systemUserName;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("catName", StringConverters.null2String(getCatName()));
        jsonObject.put("lvl", getLvl());
        jsonObject.put("systemUserId", CommonSugar.getTypedDefault(getSystemUserId(), 0L));
        jsonObject.put("systemUserName", StringConverters.null2String(getSystemUserName()));
        if(getLvl()>0){
            jsonObject.put("typeName", "类型");
        }else{
            jsonObject.put("typeName", "专业");
        }
        jsonObject.put("parentId", getParentId());
        jsonObject.put("description",StringConverters.null2String(getDescription()));
        if(getEnterprise()!=null){
            jsonObject.put("enterpriseName", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        }else{
            jsonObject.put("enterpriseName", "");
        }
        return jsonObject;
    }
}
